<?php
namespace App\Http\Controllers\common;

use App\Http\Controllers\Controller;

use DB;

class MyAgentController extends Controller{

    //获取旗下代理商id
    static public function getAgent($agentId,&$brr=[]){

        $arr = DB::table('sa_agent') -> where(['pid'=>$agentId]) -> get();
        if($arr != null){
            foreach ($arr as $v){
                $brr[] = $v;
                self::getAgent($v['id'],$brr);
            }
        }
        return $brr;
    }

    //将自身数据信息放入数组
    static public function allAgent($agentId){
        $agent = [];
        $brr = MyAgentController::getAgent($agentId);
        array_unshift($brr,DB::table('sa_agent') -> where(['id'=>$agentId]) -> first());
        foreach ($brr as $v){
            $agent[$v['id']] = $v;
        }
        return $agent;
    }

}